#ifndef __XYMODEM_HH__
#define __XYMODEM_HH__

#include "common.h"

#define SOH 0x01
#define STX 0x02
#define EOT 0x04
#define ACK 0x06
#define BSP 0x08
#define NAK 0x15
#define CAN 0x18
#define CRC 0x43

typedef enum _modem_status{
    MODEM_OK,
    MODEM_CNT,
    MODEM_CAN,
    MODEM_TIMEOUT,
    MODEM_EOF,
    MODEM_FRAME,
    MODEM_CRC_ERR,
    MODEM_EOTT,
}modem_status;

#define FILENAME_LEN 64

typedef enum{
    MODEM_TYPE_X,
    MODEM_TYPE_Y,
}mtype;

typedef struct{
    mtype type;
    bool crc_mode;
    bool tx_ack;
    bool connected;
    int file_cnt;
    bool ctn_recv;
    int nxt_num;
    int cur_num;
    int pkt_len;
    int file_len;
    int rec_err;
    char filename[FILENAME_LEN];
}tmodem;

extern int modem_recv_file(const mtype type,bool ctn,u8 *databuf,int *file_len);
#endif
